package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.bo.GoodsInfoBo;
import com.cskaoyan.bean.entity.*;
import com.cskaoyan.bean.vo.*;
import com.cskaoyan.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Auther Wenjian_Yang
 * @Date 2021/10/18
 */
@RequestMapping("admin/goods")
@RestController
public class GoodsController {
    @Autowired
    GoodsService goodsService;


    // 商品列表信息
    @RequestMapping("list")
    public BaseRespVo list(String goodsId,String goodsSn,String name,BaseParam param){
        BasePageData<Goods> data = goodsService.query(goodsId,goodsSn,name,param);
        return BaseRespVo.ok(data);
    }

    // 添加商品页面
    //下拉列表能回显所属分类和所属品牌商
    @RequestMapping("catAndBrand")
    public BaseRespVo catAndBrand(){
        CateAndBrandVo cateAndBrandVo = goodsService.getCateAndBrand();
        return BaseRespVo.ok(cateAndBrandVo);
    }

    // 创建商品
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody GoodsInfoBo goodsInfoBo){
        goodsService.create(goodsInfoBo);
        return BaseRespVo.ok();
    }

    // http://localhost:8083/admin/goods/detail?id=1110016
    // 根据商品id回显此商品信息
    @RequestMapping("detail")
    public BaseRespVo detail(Integer id){
        DetailVo detail = goodsService.detail(id);
        return BaseRespVo.ok(detail);
    }

    // http://localhost:8083/admin/goods/update
    // 修改商品信息
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody GoodsInfoVo goodsInfoVo){
        goodsService.update(goodsInfoVo);
        return BaseRespVo.ok();
    }

    //http://localhost:8083/admin/goods/delete
    // 删除商品信息
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Goods goods){
        goodsService.delete(goods);
        return BaseRespVo.ok();
    }


}
